local xiongchen = fk.CreateSkill{
  name = "xiaobai__xiongchen",
  tags = {Skill.Compulsory}
}

Fk:loadTranslationTable{
  ["xiaobai__xiongchen"] = "凶谶",
  [":xiaobai__xiongchen"] = "锁定技，你的判定流程改为依次亮出牌堆顶牌直到出现【杀】，你令此【杀】作为你的判定牌，然后获得其余亮出的牌；"..
  "若牌堆在此流程中洗牌，你分配3点雷电伤害并终止此次判定。",
  ["xiaobai__xiongchen_active"] = "凶谶",
  ["#xiaobai__xiongchen-num"] = "凶谶：分配3点雷电伤害（还剩%arg点！）",
  ["@xiaobai__xiongchen_count"] = "伤害值",

  ["$xiaobai__xiongchen1"] = "猝断之弦，其谶不远，汉中不可争。",
  ["$xiaobai__xiongchen2"] = "逆天政，背天情，丧天功，是之谓大凶。",
}


xiongchen:addEffect(fk.StartJudge, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.card then --防止被咒缚等技能截胡
      room:moveCardTo(data.card, Card.DiscardPile, nil, fk.ReasonJustMove)
    end
    local cards = {}
    while true do
      local id = room:getNCards(1)[1]
      room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, xiongchen.name, nil, true, player)
      room:delay(1000)
      local card = Fk:getCardById(id)
      data.card = card  --防止二效果炸事件后clear中data.card为空报错
      if card.trueName == "slash" then
        break
      else
        table.insert(cards, id)
        room:setPlayerMark(player, xiongchen.name, cards)  --偷懒，用于二效果炸事件后清理处理区
      end
    end
    if #cards > 0 and not player.dead then
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, xiongchen.name, nil, true)
    end
  end,
})

xiongchen:addEffect(fk.AfterDrawPileShuffle, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    local skill_event = player.room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect, true) 
    return skill_event and skill_event.data.who == player and skill_event.data.skill.name == xiongchen.name
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect)
    if e then
      room.logic:getCurrentEvent():addExitFunc(function()
        e:shutdown()
      end)
      local parent = e.parent
      if parent and parent.event == GameEvent.CardEffect then
        local effect = parent.data
        if effect.card.sub_type == Card.SubtypeDelayedTrick and room:getCardArea(effect.card:getEffectiveId()) == Card.Processing
          and not target.dead and not target:hasDelayedTrick(effect.card.name) and not table.contains(target.sealedSlots, Player.JudgeSlot)
          then
          local card = effect.card
          if card:isVirtual() then
            card = Fk:cloneCard(card.name)
            card:addSubcards(effect.card.subcards)
            card.skillNames = effect.card.skillNames
            target:addVirtualEquip(card)
          end
          room:moveCardTo(card, Player.Judge, target, fk.ReasonJustMove, taoluan.name)
        end
      end
    end
    local total = 3
    while total > 0 do
      room:setPlayerMark(player, "xiaobai__xiongchen-tmp", total)
      local _, dat = room:askToUseActiveSkill(player,{
        skill_name = "xiaobai__xiongchen_active",
        prompt = "#xiaobai__xiongchen-num:::"..total,
        cancelable = false
      })
      local to = dat.targets[1]
      room:addPlayerMark(to, "@xiaobai__xiongchen_count", dat.interaction)
      total = total - dat.interaction
    end
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:getMark("@xiaobai__xiongchen_count") > 0 then
        room:damage{
          from = player,
          to = p,
          damage = p:getMark("@xiaobai__xiongchen_count"),
          damageType = fk.ThunderDamage,
          skillName = xiongchen.name,
        }
        room:setPlayerMark(p, "@xiaobai__xiongchen_count", 0)
      end
    end
  end,
})

return xiongchen